function I = verCorrLonLat(PathTsData)
%verCoorLonLat - verification and correction of lon/lat/height coordinates
%
%       I = verCorrLonLat(PathTsData)
%
% This function reads the tsData .mat files in the folder PathTsData and,
% for each tsData object, checks the availablity of longitude, latitude
% and height data. If one or more of these data are lacking, the function 
% downloads the corresponding data from the Navada Geodetic Laboratory
% web site and upgrades the file.
% The output vector I is 1 in those cases in which the correction is 
% necessary.
%
% See also GetLonLat.

% G. Teza, 2022

files = dir(fullfile(PathTsData,'*.mat'));
nf = size(files,1);

I = false(nf,1);
for k = 1:nf
    namefk = files(k).name;
    complNamefk = fullfile(PathsData,namefk);
    tss = load(complNamefk);
    try
        tso = tss.ts;
        if isempty(tso.lat) || isempty(tso.lon) || isempty(tso.height) 
            namek = tso.statName;
            [lat,lon,ellh] = GetLonLat(namek);
            tso.lat = lat;
            tso.lon = lon;
            tso.height = ellh;
            ts = tso;
            I(k,2) = true;
            save(complNamefk,ts);
            fprintf('File %s updated\n',namefk);
        else
            fprintf('File %s - update is unnecessary\n',namefk);
        end
    catch
        fprintf('File %s is no a tsData file\n',namefk);
    end
end